
import java.io.*;

/*
ID: huangmingbo
LANG: JAVA
TASK: prefix
 */
public class prefix {
    static final int MAXL = 11;

    static Node trie;
    static BufferedReader fin;
    static PrintWriter fout;

    public static void main(String[] args) throws IOException {
        trie = new Node();
        fin = new BufferedReader(new InputStreamReader(prefix.class.getResourceAsStream("prefix.in")));
        fout = new PrintWriter(new FileWriter("prefix.out"));

        readdict();
        compute();

        fin.close();
        fout.close();
    }

    static String readword() throws IOException {
        char ch = (char) fin.read();
        while (!(ch >= 'A' && ch <= 'Z') && ch != '.') {
            ch = (char) fin.read();
        }
        StringBuilder sb = new StringBuilder();
        while ((ch >= 'A' && ch <= 'Z') || ch == '.') {
            sb.append(ch);
            ch = (char) fin.read();
        }
        return sb.toString();
    }

    static void readdict() throws IOException {
        String s = readword();
        while (!s.equals(".")) {
            Node nod = trie;
            int l = s.length();
            for (int j = l - 1; j >= 0; j--) {
                char ch = s.charAt(j);
                if (nod.next[ch - 'A'] == null) {
                    nod.next[ch - 'A'] = new Node();
                }
                nod = nod.next[ch - 'A'];
            }
            nod.isthere = true;
            s = readword();
        }
    }

    static void compute() throws IOException {
        boolean[] start = new boolean[MAXL + 1];
        char[] data = new char[MAXL + 1];
        int i = 1;
        int max = 0;
        int cnt = 1;
        int ch = fin.read();

        start[0] = true;
        while (ch != -1) {
            if (ch < 'A' || ch > 'Z') {
                ch = fin.read();
                continue;
            }
            if (i == MAXL) i = 0;
            int k = i;
            data[i] = (char) ch;
            start[i] = false;
            Node nod = trie;

            while (nod != null) {
                nod = nod.next[data[k] - 'A'];
                k--;
                if (k < 0) k = MAXL - 1;
                if (start[k] && nod != null && nod.isthere) {
                    start[i] = true;
                    max = cnt;
                    break;
                }
                if (data[k] == 0) break;
            }
            ch = fin.read();

            if (cnt > max + MAXL) break;

            i++;
            cnt++;
        }

        fout.println(max);
    }


    private static class Node {
        Node[] next;
        boolean isthere;

        Node() {
            next = new Node[26];
            isthere = false;
        }
    }

}

